//
//  WXPAuthIncomeVC.m
//  MexicoLoan
//
//  Created by WXP on 2025/2/27.
//
//

#import "WXPAuthIncomeVC.h"
#import "WXPAuthIncomeContentView.h"

@interface WXPAuthIncomeVC ()

@property (nonatomic, strong) WXPAuthIncomeContentView * viewContent;

@end

@implementation WXPAuthIncomeVC

#pragma mark - lazy
- (WXPAuthIncomeContentView *)viewContent{
    if (!_viewContent) {
        _viewContent = [WXPAuthIncomeContentView new];
        WEAKSELF
        _viewContent.blockResetAuthBtn = ^(BOOL clickable) {
            weakSelf.btnAuth.alpha = clickable ? 1 : 0.5;
            weakSelf.btnAuth.userInteractionEnabled = clickable;
        };
//        _viewHeader.emailView.blockTextFieldDidChange = ^{
//            NSString *trimmedString = [weakSelf.viewHeader.emailView.tfContent.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
//            weakSelf.viewHeader.emailView.tfContent.text = trimmedString;
//            [weakSelf.viewFooter resetEmailHint:trimmedString];
//            
////
////            [weakSelf resetEntregarBtn];
////            if(isInput){
////                //[GlobalMethod userBehaviorTrackWithPageName:KEY_VerifyPerson featureName:KEY_EMail_Input action:KEY_INPUT type:KEY_input];
////            }
//        };
    }
    return _viewContent;
}

#pragma mark - viewDidLoad
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [GlobalMethod buryPointWithPageName:KEY_VerifyIncome featureName:KEY_Page action:KEY_ENTER type:KEY_page];
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [GlobalMethod buryPointWithPageName:KEY_VerifyIncome featureName:KEY_Page action:KEY_OUT type:KEY_page];
}
- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    // 打点
    [GlobalMethod hitPointWithPageName:KEY_VerifyIncome action:KEY_Enter extInfo:nil];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self.navView resetViewWithTitle:@"Información de trabajo"];
    [self.progressView resetViewWithNum:@"4"];
    [self.progressView.moneyView resetViewWithTag:4];
    [self resetHeaderView];
    WEAKSELF
    [self.btnAuth setNoRepeatActionWithInterval:1 action:^(UIButton * _Nonnull button) {
        [NSObject clickFeedback];
        [weakSelf.btnAuth addClickAnimate];
        [weakSelf requestSubmitAuth];
    }];
    // request
    [self requestJobTypeDictList];
    [self requestIndustryDictList];
    [self requestSalaryTypeDictList];
    [self requestMonthlyIncomeDictList];
}

#pragma mark - resetHeaderView
- (void)resetHeaderView{
    self.headerView = [UIView initWithViews:@[
        self.progressView,
        [GlobalMethod getViewWithHeight:16],
        self.viewContent,
        //[GlobalMethod getViewWithHeight:(SCREEN_HEIGHT-self.btnAuth.top)],
    ]];
    self.tableView.tableHeaderView = self.headerView;
}

#pragma mark - request
// 工作类型
- (void)requestJobTypeDictList{
    [RequestApi requestCommonDictListWithType:KEY_JOB_TYPE delegate:nil success:^(NSDictionary * _Nonnull response, id  _Nonnull mark) {
        
        self.viewContent.jobTypeAry = [response arrayValueForKey:KEY_dictList];
        
    } failure:^(NSString * _Nonnull errorStr, id  _Nonnull mark) {
        
    }];
}
// 行业类型
- (void)requestIndustryDictList{
    [RequestApi requestCommonDictListWithType:KEY_INDUSTRY delegate:nil success:^(NSDictionary * _Nonnull response, id  _Nonnull mark) {
        
        self.viewContent.industryAry = [response arrayValueForKey:KEY_dictList];
        
    } failure:^(NSString * _Nonnull errorStr, id  _Nonnull mark) {
        
    }];
}
// 发薪类型
- (void)requestSalaryTypeDictList{
    [RequestApi requestCommonDictListWithType:KEY_SALARY_TYPE delegate:nil success:^(NSDictionary * _Nonnull response, id  _Nonnull mark) {
        
        self.viewContent.salaryTypeAry = [response arrayValueForKey:KEY_dictList];
        
    } failure:^(NSString * _Nonnull errorStr, id  _Nonnull mark) {
        
    }];
}
// 月收入
- (void)requestMonthlyIncomeDictList{
    [RequestApi requestCommonDictListWithType:KEY_MONTHLY_INCOME delegate:nil success:^(NSDictionary * _Nonnull response, id  _Nonnull mark) {
        
        self.viewContent.monthlyIncomeAry = [response arrayValueForKey:KEY_dictList];
        
    } failure:^(NSString * _Nonnull errorStr, id  _Nonnull mark) {
        
    }];
}

- (void)requestSubmitAuth{
    [GlobalMethod hitPointWithPageName:KEY_VerifyIncome action:KEY_Save_Start extInfo:nil];
    NSDictionary * dic = @{
        KEY_jobStatus: self.viewContent.jobStatus,
        KEY_industry: self.viewContent.industry,
        KEY_companyName: [readStr(self.viewContent.tfCompanyName.tfContent.text) removeHeadAndTailSpace],
        KEY_companyAddress: [readStr(self.viewContent.tfCompanyAddress.tfContent.text) removeHeadAndTailSpace],
        KEY_companyPhone: [readStr(self.viewContent.tfCompanyPhone.tfContent.text) removeHeadAndTailSpace],
        KEY_salaryType: self.viewContent.salaryType,
        KEY_salaryDay1: self.viewContent.salaryDay1,
        KEY_salaryDay2: readStr(self.viewContent.salaryDay2),
        KEY_monthlyIncome: self.viewContent.monthlyIncome,
    };
    [RequestApi requestSaveUserInfoWithData:dic step:KEY_INCOME_INFO delegate:self success:^(NSDictionary * _Nonnull response, id  _Nonnull mark) {
    
        [GlobalMethod hitPointWithPageName:KEY_VerifyIncome action:KEY_Save_End extInfo:nil];
        // 风控
        [GlobalMethod addRiskControlWithType:KEY_WORK startTime:self.startTime endTime:[GlobalMethod getTimeStampMillisecond]];
        // 调用获取下一步接口，跳转到该接口返回的对应认证页面
        [self requestGetNextStep];
        
    } failure:^(NSString * _Nonnull errorStr, id  _Nonnull mark) {
        
    }];
}

@end
